/*
 * @Author: xuetao 3168581151@qq.com
 * @Date: 2025-03-02
 * @LastEditors: xuetao 3168581151@qq.com
 * @LastEditTime: 2025-04-16
 * @Description: 
 */
// 工具面板组件
import 'package:flutter/material.dart';

class ToolPanel extends StatelessWidget {
  final List<ToolAction> actions; // 功能项数据
  final Color backgroundColor; // 背景颜色
  final double iconSize; // 图标尺寸
  final Color iconColor; // 图标颜色
  final int columns; // 每行显示列数
  final double spacing; // 项目间距

  const ToolPanel({
    super.key,
    required this.actions,
    this.backgroundColor = Colors.white,
    this.iconSize = 45,
    this.iconColor = Colors.black,
    this.columns = 4,
    this.spacing = 16,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 280,
      color: backgroundColor,
      child: GridView.builder(
        padding: EdgeInsets.only(top: 30, right: 16, left: 16, bottom: 16),
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: columns,
          mainAxisSpacing: spacing,
          crossAxisSpacing: spacing,
        ),
        itemCount: actions.length,
        itemBuilder: (context, index) => _buildActionItem(actions[index]),
      ),
    );
  }

  // 构建单个功能项
  Widget _buildActionItem(ToolAction action) {
    return GestureDetector(
        behavior: HitTestBehavior.opaque,
        onTap: () => {action.onAction()},
        child: Container(
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(20),
              boxShadow: [
                BoxShadow(
                  color: Colors.black12,
                  blurRadius: 4,
                ),
              ],
            ),
            child: Center(
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Icon(
                    action.icon,
                    size: iconSize,
                    color: iconColor,
                  ),
                  const SizedBox(height: 4),
                  Text(
                    action.label,
                    style: TextStyle(
                      fontSize: 12,
                      color: Colors.grey[600],
                    ),
                  ),
                ],
              ),
            )));
  }
}

// 功能项数据模型
class ToolAction {
  final IconData icon;
  final String label;
  final String type; // 用于区分操作类型
  final VoidCallback onAction; // 点击回调

  const ToolAction({
    required this.icon,
    required this.label,
    required this.type,
    required this.onAction,
  });
}
